package com.songtech.device.controller;

import com.songtech.base.common.BaseConstant;
import com.songtech.base.common.JsonResult;
import com.songtech.device.service.DeviceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @Author: yangzhicheng
 * @Date: 2018/6/20 10:01
 */
@RestController
@RequestMapping("/device")
public class DeviceController {

    Logger logger = LoggerFactory.getLogger(DeviceController.class);

    @Autowired
    private DeviceService deviceService;


    /**
     * 查询设备在线和离线数
     * @param map
     * @return
     */
    @RequestMapping(value="/deviceStatus",method = RequestMethod.GET)
    public JsonResult deviceStatus(@RequestParam  Map<String,String> map){
        Map<String, Object> hashMap = null;
        try{
            Map<String, String> dataMap  = new HashMap<>();
            //设备离线数
            int offline = deviceService.deviceOfflineCount(map);
            //设备在线数
            int online = deviceService.deviceOnlineCount(map);

            hashMap.put("offline",offline);
            hashMap.put("online",online);
        }catch (Exception ex){
            logger.error("查询设备在线和离线数异常："+ex.getMessage(),ex);
            return new JsonResult(hashMap, BaseConstant.FAIL_CODE, BaseConstant.FAIL);
        }
        return new JsonResult(hashMap, BaseConstant.SUCCESS_CODE, BaseConstant.SUCCESS);
    }







}
